/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package databook.util;

/**
 *
 * @author zach
 */
public class SimpleDoubleTransformFunction {
    private double START_VAL = 0;
    private double END_VAL = 1;
    private double HIGH_VAL = 1;
    private double LOW_VAL = 0;
    
    public SimpleDoubleTransformFunction() {
        this(0,1);
    }
    
    public SimpleDoubleTransformFunction(double start, double end) {
        this(0,1,0,1);
    }
    
    public SimpleDoubleTransformFunction(double low, double high, double start, double end) {
        LOW_VAL = low;
        HIGH_VAL = high;
        START_VAL = start;
        END_VAL = end;
    }
    
    public void setStartValue(double val) {
        START_VAL = val;
    }
    
    public void setEndValue(double val) {
        END_VAL = val;
    }
    
    public void setLowValue(double low) {
        LOW_VAL = low;
    }
    
    public void setHighValue(double high) {
        HIGH_VAL = high;
    }
    
    public double getValue(double val) {
        if (val < LOW_VAL) val = LOW_VAL;
        if (val > HIGH_VAL) val = HIGH_VAL;
        if (HIGH_VAL == LOW_VAL) return START_VAL;
        double diff = (val - LOW_VAL)/(double)(HIGH_VAL - LOW_VAL);    
        return START_VAL + ((END_VAL - START_VAL)*diff);        
    }
    
    public void weigh(double val) {
        if (val < LOW_VAL)
            LOW_VAL = val;
        if (val > HIGH_VAL) 
            HIGH_VAL = val;
    }
    
    public double getHighValue() {
        return HIGH_VAL;
    }
}
